<?php

/**
 * This is the model class for table "content".
 *
 * The followings are the available columns in table 'content':
 * @property integer $id
 * @property string $name
 * @property string $text
 * @property integer $seq_number
 * @property string $icon_file_name
 * @property string $created_by
 * @property string $created_date
 * @property string $modified_by
 * @property string $modified_date
 * @property string $active_start_date
 * @property string $active_end_date
 * @property integer $parent_id
 * @property integer $content_type_id
 * @property integer $application_id
 * @property integer $content_status_id
 * @property integer $deleted
 *
 * The followings are the available model relations:
 * @property ContentStatus $contentStatus
 * @property ContentType $contentType
 * @property Application $application
 * @property ContentDocument[] $contentDocuments
 * @property ContentFile[] $contentFiles
 * @property ContentLink[] $contentLinks
 * @property ContentPermission[] $contentPermissions
 */
class VContent extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return VContent the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'content';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('content_type_id, application_id, content_status_id', 'required'),
			array('seq_number, parent_id, content_type_id, application_id, content_status_id, deleted', 'numerical', 'integerOnly'=>true),
			array('name, icon_file_name, created_by, modified_by', 'length', 'max'=>255),
			array('text, created_date, modified_date, active_start_date, active_end_date', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, text, seq_number, icon_file_name, created_by, created_date, modified_by, modified_date, active_start_date, active_end_date, parent_id, content_type_id, application_id, content_status_id, deleted', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'contentStatus' => array(self::BELONGS_TO, 'ContentStatus', 'content_status_id'),
			'contentType' => array(self::BELONGS_TO, 'ContentType', 'content_type_id'),
			'application' => array(self::BELONGS_TO, 'Application', 'application_id'),
			'contentDocuments' => array(self::HAS_ONE, 'ContentDocument', 'content_id'),
			'contentFiles' => array(self::HAS_ONE, 'ContentFile', 'content_id'),
			'contentLinks' => array(self::HAS_ONE, 'ContentLink', 'content_id'),
			'contentPermissions' => array(self::HAS_MANY, 'ContentPermission', 'content_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Name',
			'text' => 'Text',
			'seq_number' => 'Seq Number',
			'icon_file_name' => 'Icon File Name',
			'created_by' => 'Created By',
			'created_date' => 'Created Date',
			'modified_by' => 'Modified By',
			'modified_date' => 'Modified Date',
			'active_start_date' => 'Active Start Date',
			'active_end_date' => 'Active End Date',
			'parent_id' => 'Parent',
			'content_type_id' => 'Content Type',
			'application_id' => 'Application',
			'content_status_id' => 'Content Status',
			'deleted' => 'Deleted',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('text',$this->text,true);
		$criteria->compare('seq_number',$this->seq_number);
		$criteria->compare('icon_file_name',$this->icon_file_name,true);
		$criteria->compare('created_by',$this->created_by,true);
		$criteria->compare('created_date',$this->created_date,true);
		$criteria->compare('modified_by',$this->modified_by,true);
		$criteria->compare('modified_date',$this->modified_date,true);
		$criteria->compare('active_start_date',$this->active_start_date,true);
		$criteria->compare('active_end_date',$this->active_end_date,true);
		$criteria->compare('parent_id',$this->parent_id);
		$criteria->compare('content_type_id',$this->content_type_id);
		$criteria->compare('application_id',$this->application_id);
		$criteria->compare('content_status_id',$this->content_status_id);
		$criteria->compare('deleted',$this->deleted);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}